﻿using System;


using System.Text;
using IAM.Interface.Model.Interface;
using System.Web;
using System.Reflection;

namespace IAM.Interface.Model
{
    /// <summary>
    /// 权限层次定义，定义了单个权限层次信息
    /// </summary>
    public class DimensionLevel : AbstractConvertObject,IConvertXml
    {
        #region 属性
        private string _id = "";
        private string _display = "";
        /// <summary>
        /// 权限层次标识
        /// </summary>
        public string ID
        {
            get
            {
                return _id;
            }
            set
            {
                _id = value;
            }
        }
        /// <summary>
        /// 权限层次显示名
        /// </summary>
        public string Display
        {
            get
            {
                return _display;
            }
            set
            {
                _display = value;
            }
        }
        #endregion
        #region IConvertXml

        public string XMLBoday
        {
            get
            {
                StringBuilder _xml = new StringBuilder();
                _xml.Append("<DimensionLevel");
                _xml.Append(" ID=\"" + IAM.Interface.Common.EnDeCoding.Encode(this.ID) + "\"");
                _xml.Append(" Display=\"" + IAM.Interface.Common.EnDeCoding.Encode(this.Display )+ "\"");
                _xml.Append(" />");

                return _xml.ToString();
            }


        }

        public string XMLFinis
        {
            get
            {
                return "";
            }
        }
        public string XML
        {
            get
            {
                return XMLBoday + XMLFinis;
            }
        }
        #endregion
        #region AbstractConvertObject
        public override object ConvertToObject()
        {
            this.ID = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.Attributes["ID"].InnerText);
            this.Display = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.Attributes["Display"].InnerText);
            return this;
        }
        #endregion
        #region 重写Equals
        /// <summary>
        /// 确定指定的 DimensionLevel 对象是否等效于当前 DimensionLevel
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            DimensionLevel dl = null;
            try
            {
                dl = (DimensionLevel)obj;
            }
            catch
            {
                return false;
            }
            bool result = true;
            if (this.ID != dl.ID)
            {
                result = false;
            }
            else if (this.Display != dl.Display)
            {
                result = false;
            }
            return result;
        }

        #endregion
        #region 重写GetHashCode
        /// <summary>
        /// 哈希函数
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            int result = 1;
            PropertyInfo[] pi = this.GetType().GetProperties();
            foreach (PropertyInfo onofpi in pi)
            {
                result = result + onofpi.GetHashCode();
            }
            return result;
        }
        #endregion
    }
}
